package com.manli.api.controller;

import java.util.Arrays;
import java.util.Map;

import com.manli.api.dao.SysWechatConfigDao;
import com.manli.api.dto.SysWechatConfig;
import com.manli.api.pojo.Result;
import com.manli.api.util.WeChatConfigUtil;
import com.manli.api.util.WeChatOverUtil;
import com.manli.common.utils.StringUtil;
import com.manli.wechat.utils.WeChat;
import com.manli.wechat.utils.WeChatMenu;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.manli.api.base.annotation.Permissions;
import com.manli.api.dto.GeneratorTest;
import com.manli.api.service.GeneratorTestService;
import springfox.documentation.spring.web.plugins.Docket;


/**
 * 代码生成测试表
 *
 * @author manli
 * @email 
 * @date 2020-04-01 14:50:37
 */
//@Api(value="/generatortest", tags="代码生成测试表")
@RestController
@RequestMapping("api/generatortest")
@Slf4j
public class GeneratorTestController {
    @Autowired
    private GeneratorTestService generatorTestService;
    @Autowired
    private WeChatConfigUtil weChatConfigUtil;
    @Autowired
    private WeChatOverUtil weChatOverUtil;


    /**
     * 列表
     */
    @ApiOperation(value = "代码生成测试表列表",notes = "")
    @GetMapping("/list")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result list(@RequestParam Map<String, Object> params)throws Exception{
        return generatorTestService.queryPage(params);
    }

    /**
     * 全部数据信息
     */
    @ApiOperation(value = "代码生成测试表全部数据信息",notes = "")
    @GetMapping("/all")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result all()throws Exception{


//        String appid = "wxaacee0223003a3fa";
//        SysWechatConfig sysWechatConfig = weChatConfigUtil.getWeChatByAppid(appid);

        //创建对象
        WeChatMenu weChat = new WeChatMenu("wxaacee0223003a3fa","21853a291d8e2a10c2181ae9f958937a");
        //token,ticket初始化
        weChatOverUtil.init(weChat);
        //调用微信api
//        weChat.deleteMenu(weChatOverUtil.getAccessToken(weChat));


        return null;
//        return generatorTestService.queryAll();
    }

    /**
     * 单条信息
     */
    @ApiOperation(value = "代码生成测试表单条信息",notes = "代码生成测试表单条信息")
    @GetMapping("/info/{id}")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result info(@PathVariable("id") Integer id){
        return generatorTestService.getById(id);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "代码生成测试表保存",notes = "代码生成测试表保存")
    @PostMapping("/save")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result save(GeneratorTest generatorTest){
        return generatorTestService.save(generatorTest);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "代码生成测试表修改",notes = "代码生成测试表修改")
    @PostMapping("/update")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result update(GeneratorTest generatorTest){
        return generatorTestService.updateById(generatorTest);
    }

    /**
     * 删除单条数据
     */
    @ApiOperation(value = "代码生成测试表删除",notes = "代码生成测试表删除")
    @ApiImplicitParam(name = "ids", value = "id",dataType = "int", required = true)
    @DeleteMapping("/delete")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result delete(Integer id){
        return generatorTestService.removeById(id);
    }

    /**
     * 删除多条数据
     */
    @ApiOperation(value = "代码生成测试表删除",notes = "代码生成测试表删除")
    @ApiImplicitParam(name = "ids", value = "id数组,json字符串",dataType = "id数组,json字符串", required = true)
    @PostMapping("/deleteIds")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_OPEN)
    public Result deleteIds(@RequestBody Integer[] ids){
        return generatorTestService.removeByIds(Arrays.asList(ids));
    }

}
